import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AdmItemApplyVO, AdmItemApplyForm, AdmItemApplyQuery } from '@/api/general/administration/item/apply/types';

/**
 * 查询物资采购申请列表
 * @param query
 * @returns {*}
 */

export const listAdmItemApply = (query?: AdmItemApplyQuery): AxiosPromise<AdmItemApplyVO[]> => {
  return request({
    url: '/system/admItemApply/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询物资采购申请详细
 * @param id
 */
export const getAdmItemApply = (id: string | number): AxiosPromise<AdmItemApplyVO> => {
  return request({
    url: '/system/admItemApply/' + id,
    method: 'get'
  });
};

/**
 * 新增物资采购申请
 * @param data
 */
export const addAdmItemApply = (data: AdmItemApplyForm) => {
  return request({
    url: '/system/admItemApply',
    method: 'post',
    data: data
  });
};

/**
 * 修改物资采购申请
 * @param data
 */
export const updateAdmItemApply = (data: AdmItemApplyForm) => {
  return request({
    url: '/system/admItemApply',
    method: 'put',
    data: data
  });
};

/**
 * 删除物资采购申请
 * @param id
 */
export const delAdmItemApply = (id: string | number | Array<string | number>) => {
  return request({
    url: '/system/admItemApply/' + id,
    method: 'delete'
  });
};

/**
 * 导入物品 Excel
 * @param file 文件对象
 * @param bookStoreBo 额外参数对象
 */
export const importItems = (file: File, bookStoreBo: AdmItemApplyForm): AxiosPromise<void> => {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('data', JSON.stringify(bookStoreBo));

  return request({
    url: '/system/admItemApply/import',
    method: 'post',
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' }
  });
};
